package com.cy.dda.service.tencent.impl;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import com.cy.dda.comm.utils.JsonObjectMapper;
import com.cy.dda.service.BaseService;
import com.cy.dda.service.tencent.TencentMapService;

/**
 * 对接腾讯地图服务api
 *
 * @author: tanyilin
 * @create: 2018年11月30日 下午3:38:13
 */
@Service
public class TencentMapServiceImpl extends BaseService implements TencentMapService {

	@Autowired
    private RestTemplate restTemplate;
	
	@Value("${tencent.map.key}")
	private String key;
	
	@Value("${tencent.map.get-address-url}")
	private String getAddressUrl;
	
	@Override
	public Map<String, Object> getAddress(String location) {
		
		Map<String, String> paramMap = new HashMap<String, String>();
		paramMap.put("location", location);
		paramMap.put("key", key);
		ResponseEntity<String> responseEntity = restTemplate.getForEntity(getAddressUrl, String.class, paramMap);
		Map<String, Object> resultMap = JsonObjectMapper.read(responseEntity.getBody(), Map.class);
		int status = (int) resultMap.get("status");
		state(status == 0, "地址解析服务请求失败");
		return resultMap;
	}

	
}
